// GUI COMPONENT - SCROLLED PANEL.

import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;

public class ItemViewer extends JScrollPane {
	private static final long serialVersionUID = -5330894309299528820L;
	
	private JList<String> content;
	private DefaultListModel<String> listModel;

	public ItemViewer(String title) {
		setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER);
		setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_ALWAYS);
		setBorder(BorderFactory.createTitledBorder(title));
		
		listModel = new DefaultListModel<String>();
        content = new JList<String>(listModel);
        setViewportView(content);
	}
	
	public void addItem(final String newItem) {
		SwingUtilities.invokeLater(new Runnable() { 
			public void run() {
				listModel.addElement(newItem);
			}
		});
	}
	
	public void selectItem(final int i) {
		SwingUtilities.invokeLater(new Runnable() { 
			public void run() {
				content.setSelectedIndex(i);
			}
		});
	}

}
